import com.tmri.clean.init.CleanProperties;
import com.tmri.clean.init.OracleHandler;
import org.csource.fastdfs.StorageClient;
import org.csource.fastdfs.StorageServer;
import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerServer;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.util.FileCopyUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @Description TODO
 * @Date 2021/10/19 14:18
 * @Created by xielx
 */
public class MockData {
    private static JdbcTemplate jdbcTemplate;
    private static StorageClient storageClient;

    public static void main(String[] args) throws Exception {


        if (1==1) {
            return;
        }

        CleanProperties.init();
        TrackerClient tracker = new TrackerClient();
        TrackerServer trackerServer = tracker.getTrackerServer();
        StorageServer storageServer = null;
        storageClient = new StorageClient(trackerServer, storageServer);
        jdbcTemplate = OracleHandler.getJdbcTemplate();
        File dir = new File("C:\\Users\\Charles\\Pictures\\Camera Roll");
        File[] pics = dir.listFiles();
        List<Object[]> picList = new ArrayList<>();
        for (File pic : pics) {
            Object[] obj = new Object[2];
            obj[0] = FileCopyUtils.copyToByteArray(pic);
            obj[1] = pic.getName().substring(pic.getName().lastIndexOf(".")+1);
            picList.add(obj);
        }
        String sql = "insert into net_rural_dtgl_files (BM, PBM, FROMTABLE, CONTENT_TYPE, FILE_SIZE, FILE_NAME, FILE_PATH, FILE_MD5, ADDUSER, ADDTIME, ISDEL, DELTIME, SFDM, CSBJ, GXSJ, BBH, FJLB, CS_CSBJ, CS_GXSJ, CS_BBH, CS_BZ)\n" +
            "values (?, '5100161008014519363711', 'NET_RURAL_DTGL_QDGZ', 'jpg', 93581, 'QQ图片20161008093435', ?, '414DA16D498B49DBF09365D93E66AAC6', '5100160817000000324405', to_date('08-10-2016 09:34:48', 'dd-mm-yyyy hh24:mi:ss'), 0, null, '5100', '1', to_date('08-10-2016 09:34:48', 'dd-mm-yyyy hh24:mi:ss'), null, null, '0', to_date('03-09-2018 15:38:45', 'dd-mm-yyyy hh24:mi:ss'), null, null)";
        List<Object[]> bbs = new ArrayList<>();
        Random rd = new Random();
        for (int i = 0; i < 1245; i++) {
            Object[] obj = picList.get(rd.nextInt(picList.size()));
            String[] result = storageClient.upload_file((byte[]) obj[0], (String)obj[1], null);
            bbs.add(new Object[]{System.currentTimeMillis()+""+i,"/"+result[0]+"/"+result[1]});
        }
        jdbcTemplate.batchUpdate(sql,bbs);
        jdbcTemplate.execute("commit");
    }
}
